using System;
using UnityEngine;
using UnityEngine.UI;

public class SpawnEffectOnMouse : MonoBehaviour
{
	[Serializable]
	public class chainEffect
	{
		[NonSerialized]
		public int firstvariableisinvisible;

		public string name;

		public bool isPlayed;

		public float Yoffset;

		public bool RotateRandomizer;

		public GameObject Effect;
	}

	public chainEffect[] chainEffectList;

	public int activevariation;

	public Text UIText;

	private Ray ray;

	private RaycastHit hit;

	private void Start()
	{
		CheckName();
	}

	private void Update()
	{
		if (UnityEngine.Input.GetKeyDown(KeyCode.D) || Input.GetButtonDown("Fire2"))
		{
			NextEffect(increase: true);
		}
		if (UnityEngine.Input.GetKeyDown(KeyCode.A))
		{
			NextEffect(increase: false);
		}
		ray = Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition);
		if (Physics.Raycast(ray, out hit) && Input.GetButtonDown("Fire1"))
		{
			GameObject effect = chainEffectList[activevariation].Effect;
			Vector3 point = hit.point;
			float x = point.x;
			Vector3 point2 = hit.point;
			float y = point2.y + chainEffectList[activevariation].Yoffset;
			Vector3 point3 = hit.point;
			GameObject gameObject = UnityEngine.Object.Instantiate(effect, new Vector3(x, y, point3.z), Quaternion.FromToRotation(Vector3.up, hit.normal));
		}
	}

	private void NextEffect(bool increase)
	{
		if (increase)
		{
			activevariation++;
			if (activevariation >= chainEffectList.Length)
			{
				activevariation = 0;
			}
		}
		if (!increase)
		{
			activevariation--;
			if (activevariation < 0)
			{
				activevariation = chainEffectList.Length - 1;
			}
		}
		CheckName();
	}

	private void CheckName()
	{
		UIText.text = "#" + activevariation + " " + chainEffectList[activevariation].name;
	}
}
